<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 600px;
            margin: 100px auto;
        }
        
        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            background: url(images/mess.png) no-repeat left center;
            padding-left: 20px;
        }
        
        .wrong {
            color: red;
            background: url(images/wrong.png) no-repeat;
        }
        
        .right {
            color: green;
            background: url(images/right.png) no-repeat;
        }
    </style>
</head>

<body>
    <div class="register">

        <input type="password" class="ipt">
        <p class="message ">请输入6-16位密码</p>

    </div>
    <script>
        var register = document.querySelector('.register')
        var ipt = register.children[0]
        var message = register.children[1]
        ipt.onblur = function() {
            if (ipt.value.trim().length < 6 || ipt.value.trim().length > 16) {
                message.className = 'message wrong'
                message.innerHTML = '您输入的位数不对要求6-16位'

            } else {
                message.className = 'message right'
                message.innerHTML = '您输入的正确'


            }
        }
    </script>
</body>

</html>